package com.suoluo.zenapp.common.config;

import java.util.Properties;

public class SystemConfigImpl implements SystemConfig {

	private Properties pro;

	public SystemConfigImpl(Properties properties) {
		this.pro = properties;
	}

	@Override
	public int getInt(String key, int defaultValue) {
		Object obj = getProperty(pro, key, defaultValue);
		return Integer.parseInt(obj.toString());
	}

	@Override
	public String getString(String key, String defaultValue) {
		Object obj = getProperty(pro, key, defaultValue);
		return (String) obj;
	}

	@Override
	public double getDouble(String key, double defaultValue) {
		Object obj = getProperty(pro, key, defaultValue);
		return (Double) obj;
	}

	private Object getProperty(Properties props, String key, Object defaultValue) {
		if (props == null) {
			return defaultValue;
		}
		Object strValue = props.getProperty(key);
		if (strValue == null) {
			return defaultValue;
		}
		return strValue;
	}
}
